﻿using System;
using System.Data;
using System.Data.SqlServerCe;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Common.Entities;

namespace Common.Models
{
    public class BuyerRepository
    {
        public List<Buyer> GetBuyers()
        {
            List<Buyer> buyers = new List<Buyer>();
            using (SqlCeConnection connection = WorkDataBase.CreateConnection())
            {
                if (connection.State != ConnectionState.Open)
                    connection.Open();

                string sqlQuery = "SELECT NameClient, IdBuyer FROM Buyers";
                using (SqlCeCommand command = new SqlCeCommand(sqlQuery, connection))
                {
                    using (SqlCeDataReader dr = command.ExecuteReader())
                    {
                        int idBuyer = dr.GetOrdinal("IdBuyer");
                        int nameClient = dr.GetOrdinal("NameClient");
                        while (dr.Read())
                        {
                            Buyer buyer = new Buyer();
                            buyer.IdBuyer = dr.GetInt32(idBuyer);
                            buyer.NameBuyer = dr.GetString(nameClient);
                           // buyer.BuyPoints = DataManager.GetInstance().BuyPoints.GetBuyPointsByBuyer(buyer.IdBuyer);
                           // buyer.BuyPoints = new List<BuyPoint>();
                            buyers.Add(buyer);
                        }
                        return buyers;
                    }
                }
            }

        }
    }
}
